<?php namespace Common\Model;
use Hdphp\Model\Model;
/**
 * 订单模型
 */
class Ord extends Model
{
	protected $table = "ord";
	/**
	 * 添加
	 */
	public function store()
	{
		$ototal = "";
		foreach($_SESSION['order'] as $k=>$v)
		{
		  $ototal += $v['total'];	
		}
		$onumber=$_SESSION['id'].time().rand(1000,9999);
		$aid = $_POST['aid'];
		$adData = Db::table('address')->where('aid',$aid)->first();
		$oaddress = $adData['ad'];
		$oname = $adData['name'];
		//往ord里面添数据
		$data = array(
		  'ostatus'=>1,
		  'sendtime'=>time(),
		  'ototal'=>$ototal,
		  'oaddress'=>$oaddress,
		  'oname'=>$oname,
		  'onumber'=>$onumber,
		  'order_uid'=>$_SESSION['id'],
		);
		$oid=$this->add($data);
		//实例化订单列表
		$OrdlistModel = new \Common\Model\Ordlist;
		foreach($_SESSION['order'] as $k=>$v)
		{
			$odata = array(
			  'ordlist_num'=>$v['num'],
			  'ordlist_price'=>$v['total'],
			  'ordlist_com'=>$_POST['com'][$k],
			  'ordlist_oid'=>$oid,
			  'ordlist_goods_id'=>$v['id'],
			);
			$OrdlistModel->add($odata);
		}
	}
}
